import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../../tool/assets.dart';
import 'eq_item.dart';

class EqMiddle extends StatefulWidget {
  const EqMiddle({super.key});

  @override
  State<EqMiddle> createState() => _EqMiddleState();
}

class _EqMiddleState extends State<EqMiddle> {
  Widget buildTextButton(String text, bool select, Color color, void Function() ontap) {
    return Expanded(
      child: myTextButton(
        radius: 4,
        // height: 16,
        select: select,
        colors: [color, color],
        onTap: ontap,
        child: Center(child: Text(text, style: font30)),
      ),
    );
  }

  Widget textTips(text) {
    return RotatedBox(
      quarterTurns: -1, // 逆时针旋转90度（文字竖直）
      child: Container(
        child: Text(
          text,
          style: const TextStyle(fontSize: 10, color: Colors.black, fontWeight: FontWeight.bold, height: 1),
        ),
      ),
    );
  }

  Widget rotateWidget1() {
    return RotatedBox(
      quarterTurns: -1, // 逆时针旋转90度（文字竖直）
      child: Container(
        width: 14,
        height: 14,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(7), color: Color_green),
        child: const Align(
          alignment: Alignment.topCenter,
          child: Text(
            '7',
            style: TextStyle(fontSize: 10, color: Colors.black, fontWeight: FontWeight.bold),
            textAlign: TextAlign.center,
          ),
        ),
      ),
    );
  }

  Widget rotateWidget2() {
    return Container(
        width: 14,
        height: 14,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(7), color: Color_thumbColor));
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 2, bottom: 2),
      child: Obx(() {
        var global = globalController.rxModel.value;
        var ch = global.current_ch;
        return Row(
          children: [
            ///左边 F, Q, GAIN.
            SizedBox(
                width: 50,
                child: Column(
                  spacing: 10,
                  children: [
                    buildTextButton('F', globalController.eqType.value == EditEQType.isFreq, Color_green,
                        () => globalController.updateSignEditType(EditEQType.isFreq)),
                    buildTextButton('Q', globalController.eqType.value == EditEQType.isQ, Color_yellow,
                        () => globalController.updateSignEditType(EditEQType.isQ)),
                    // Expanded(
                    //   child: Row(
                    //     mainAxisAlignment: MainAxisAlignment.center,
                    //     children: [
                    //       Column(
                    //         spacing: 2,
                    //         mainAxisAlignment: MainAxisAlignment.center,
                    //         children: [textTips('7- BAND'), rotateWidget1()],
                    //       ),
                    //       Column(
                    //         mainAxisAlignment: MainAxisAlignment.center,
                    //         children: [
                    //           textTips('15- BAND'),
                    //           rotateWidget2(),
                    //           const SizedBox(
                    //               height: 10, child: Text('+', style: TextStyle(color: Colors.black, height: 0.8))),
                    //           rotateWidget1()
                    //         ],
                    //       )
                    //     ],
                    //   ),
                    // ),
                    buildTextButton('dB', globalController.eqType.value == EditEQType.isGain, Color_theme,
                        () => globalController.updateSignEditType(EditEQType.isGain)),
                  ],
                )),

            ///右边
            Expanded(
              child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
                const padding = EdgeInsets.all(0);
                double gap = 0;
                int length = ch.sign_list.length;
                double w = (constraints.maxWidth - padding.left - padding.right - (length - 1) * gap) / length;

                return GridView.builder(
                    physics: const NeverScrollableScrollPhysics(),
                    padding: padding,
                    itemCount: length,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: length,
                        crossAxisSpacing: gap,
                        mainAxisSpacing: 5,
                        childAspectRatio: w / (constraints.maxHeight - padding.top - padding.bottom)),
                    itemBuilder: (BuildContext context, index) => EqItem(index: index));
              }),
            ),
          ],
        );
      }),
    );
  }
}
